package com.gxa.dr2.controller;

import com.gxa.dr2.dto.Response;
import com.gxa.dr2.dto.ResultDTO;
import com.gxa.dr2.pojo.User;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test")
public class TestController {


    @RequestMapping(value = "/index",method = {RequestMethod.GET, RequestMethod.POST})
    public String index(){
        return "Hello SpringBoot!!!";
    }


    /**
     * 测试接收参数-RequestParam
     * @param name
     * @return
     */
    @PostMapping("/param")
    public ResultDTO testParam(@RequestParam(name = "sersrstt") String name){
        return new ResultDTO(200, "success", name);
    }


    /**
     * 测试接收参数-PathVariable
     * @param id
     * @return
     */
    @DeleteMapping("/param2/{id}/{name}")
    public ResultDTO testParam2(@PathVariable Integer id,@PathVariable String name){
        return new ResultDTO(200, "success", id+"----"+name);
    }


    /**
     * 测试接收参数-对象
     * @param user
     * @return
     */
    @PostMapping("/object")
    public ResultDTO testObject(User user){
        return new ResultDTO(200, "success", user);
    }

    /**
     * 测试接收参数-对象-json
     * @param user
     * @return
     */
    @PostMapping("/object/json")
    public ResultDTO testObjectJson(@RequestBody User user){
        return Response.success(user);
    }
}
